package com.shujia.base;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;

/*
    使用jedis连接redis集群
 */
public class RedisApi2 {
    public static void main(String[] args) {
        //public JedisCluster(Set<HostAndPort> nodes)
        //将每一个redis服务封装成一个HostAndPort类的对象，添加到Set集合中
        HashSet<HostAndPort> set = new HashSet<>();
        //public HostAndPort(String host, int port)
        set.add(new HostAndPort("master",8000));
        set.add(new HostAndPort("master",8001));
        set.add(new HostAndPort("master",8002));
        set.add(new HostAndPort("master",8003));
        set.add(new HostAndPort("master",8004));
        set.add(new HostAndPort("master",8005));

        //将set集合作为redis集群对象的参数，来创建操作redis集群的对象
        JedisCluster jedisCluster = new JedisCluster(set);

        //就将jedisCluster当作一个redis去使用就可以了
        jedisCluster.set("height","180cm");




        //关闭连接
        jedisCluster.close();
    }
}
